package com.fcy.musicplayer.util

import android.widget.ImageView
import androidx.annotation.DrawableRes
import androidx.databinding.BindingAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.TransitionOptions
import com.bumptech.glide.request.RequestOptions
import jp.wasabeef.glide.transformations.BlurTransformation

@BindingAdapter(
    "urlSrc",
    "placeHolder",
    "BlurTransformation_radius",
    "BlurTransformation_sampling",
    requireAll = false
)
fun setImgUrl(
    view: ImageView,
    url: String?,
    @DrawableRes placeHolder: Int?,
    bt_r: Int?,
    bt_s: Int?
) {
    url?.apply {
        val load = Glide.with(view).load(this)
        LoggerUtil.d("====$bt_r ||| $bt_s")
        placeHolder?.also { load.placeholder(it) }
        bt_r?.also {
            bt_s?.apply {
                load.apply(RequestOptions.bitmapTransform(BlurTransformation(bt_r, bt_s)))
            }
        }
        load.into(view)
    }
}